(function() {
  app.controller('bank_bindCtrl', function($rootScope, $scope, $timeout, $state, tradeApi, alertTip, $http) {
    $scope.bank_bind = {};
    $scope.selected = {

    };
    $scope.close_flag = true;
    $scope.init = function() {
      $scope.global.set_header({
        header_right_text: '保存',
        header_right_fun: function() {
          $scope.selected.bank_code = $scope.selected.param;
          tradeApi.query({
            funcId: '300010',
            data: angular.extend($scope.bank_bind, $scope.selected)
          }).then(function(res) {

            alertTip.open({
              msg: '绑定成功',
              state: 1,
            });
            $timeout(function() {
              window.history.back();
            }, 1500);

          });
        },
      });

    };

    $scope.select_ = function(it, $event) {
      $($event.target).blur();

      $scope.confirmview = true;
      if (it === 'bank') {
        $scope.type = 'bank_name';
        $scope.sele_title = '请选择银行卡';
        tradeApi.query({
          funcId: '000000',
          data: {}
        }).then(function(res) {
          $scope.sourceObj = [];
          angular.forEach(res, function(item, i) {
            var obj = {};
            obj.text = item.bank_name;
            obj.param = item.bank_code;
            $scope.sourceObj.push(obj);
          });
        });
        $scope.close_flag = true;
      }
      if (it === 'place') {
        $scope.type = 'open_province';
        $scope.sele_title = '请选择省份';

        $scope.sourceObj = [];
        $http.get('./public/static/provincial-city.json').then(function(res) {
          angular.forEach(res.data, function(item, i) {
            var obj = {};
            obj.text = i;
            $scope.sourceObj.push(obj);
          });
        });
        $scope.close_flag = false;
      }
    };

    $scope.getPlace = function() {
      $scope.sele_title = '请选择地区';

      $http.get('../public/static/provincial-city.json').then(function(res) {
        var arr;
        $scope.sourceObj = [];
        angular.forEach(res.data, function(item, i) {
          if (i === $scope.selected.open_province) {
            arr = item;
          }
        });
        angular.forEach(arr, function(item) {
          var obj = {};
          obj.text = item;
          $scope.sourceObj.push(obj);
        });
      });
      $scope.type = 'open_city';
      $scope.close_flag = true;
    };
  });
})();
